﻿/*
 * 版权所有 2024 Rapid Software LLC
 * 
 * 根据 Apache 许可证 2.0 版（“许可证”）获得许可;
 * 除非符合许可，否则您不得使用此文件.
 * 您可以在以下位置获取许可证的副本
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * 
 * Product  : Rapid SCADA
 * Module   : ScadaCommCommon
 * Summary  : Defines functionality to access the communication line features
 * 
 * Author   : Mikhail Shiryaev
 * Created  : 2020
 * Modified : 2022
 */

using Scada.Comm.Channels;
using Scada.Comm.Config;
using Scada.Comm.Devices;
using Scada.Data.Models;
using Scada.Log;
using System;
using System.Collections.Generic;

namespace Scada.Comm.Drivers
{
    /// <summary>
    /// Defines functionality to access the communication line features.
    /// 定义用于访问通信线路要素的功能。
    /// <para>Определяет функциональность для доступа к функциям линии связи.</para>
    /// </summary>
    public interface ILineContext
    {
        /// <summary>
        /// 获取通信线路配置。
        /// </summary>
        LineConfig LineConfig { get; }

        /// <summary>
        /// 获取通信线路号。
        /// </summary>
        int CommLineNum { get; }

        /// <summary>
        /// 获取通信线路标题。
        /// </summary>
        string Title { get; }

        /// <summary>
        /// 获取通信线路日志。
        /// </summary>
        ILog Log { get; }

        /// <summary>
        /// 获取通信线路的共享数据。
        /// </summary>
        IDictionary<string, object> SharedData { get; }

        /// <summary>
        /// Get 沟通渠道.
        /// </summary>
        ChannelLogic Channel { get; }


        /// <summary>
        /// 选择通信线路上的所有设备。
        /// </summary>
        IEnumerable<DeviceLogic> SelectDevices();

        /// <summary>
        /// 选择通信线路上满足条件的设备。
        /// </summary>
        IEnumerable<DeviceLogic> SelectDevices(Func<DeviceLogic, bool> predicate);

        /// <summary>
        /// 按设备编号获取设备。
        /// </summary>
        bool GetDevice(int deviceNum, out DeviceLogic deviceLogic);

        /// <summary>
        /// 按数字地址获取设备。
        /// </summary>
        bool GetDeviceByAddress(int numAddress, out DeviceLogic deviceLogic);

        /// <summary>
        /// 按字符串地址获取设备。
        /// </summary>
        bool GetDeviceByAddress(string strAddress, out DeviceLogic deviceLogic);

        /// <summary>
        /// 将 telecontrol 命令排入队列。
        /// </summary>
        void EnqueueCommand(TeleCommand cmd);
    }
}
